<template>
    <el-popover trigger="click">
      <div class="header-tip-box" >
        <template v-if="headerTip.isMessage">
          <div style="line-height: 12px;margin-top: 12px">
            <span class="header-tip-title">消息盒</span>
          </div>
          <el-divider></el-divider>
          <no-tip v-if="!content || content.message.length===0"/>
          <template v-else >
            <header-tip-content v-for="(item,index) of content.message" :key="`message_${index}`"  :type="item.type" :content="item" @click="doClickNotice('message',item,`message_${index}`)" :index="`message_${index}`"/>
          </template>
        </template>
        <el-tabs v-else v-model="activeName">
          <el-tab-pane v-for="(info,index) in headerTip.tabInfos" :key="`tip_${index}`" :name="`tip_${index}`">
            <span slot="label" v-if="!content || content[info.key].length===0">{{ info.label }}</span>
            <el-badge v-else slot="label" :value="content[info.key].length">
              <span >{{ info.label }}</span>
            </el-badge>
            <no-tip v-if="!content || content[info.key].length===0"/>
            <div v-else style="padding-top: 5px">
              <header-tip-content :key="`${info.key}_${index}`" v-for="(item,index) of content[info.key]" :type="item.type" :content="item" @click.native="doClickNotice(info.key,item,`${info.key}_${index}`)" :index="`${info.key}_${index}`"/>
            </div>
          </el-tab-pane>
        </el-tabs>
        <svg-icon class="header-tip-del-icon" icon-class="delete"/>
      </div>
      <div slot="reference">
        <slot></slot>
      </div>
    </el-popover>
</template>

<script>
import HeaderTipContent from "@/components/header-tip/content.vue";
import NoTip from "@/components/header-tip/noTip.vue";

export default {
  name: "index",
  components: { NoTip, HeaderTipContent},
  provide() {
    return {
      rootHeaderTip: this
    }
  },
  data() {
    return {
      currentIndex: '',
      activeName:'tip_0'
    }
  },
  computed: {
    headerTip(){
      return this.$store.state.setting.headerTip
    },
    content(){
      return this.$store.getters.headerTipContent
    },
  },
  methods: {
    doClickNotice(type,content,index) {
      this.currentIndex = index
      this.$store.commit('SET_CURRENT_CLICK_HEADER_TIP',{type,content,index})
    },
  },
}
</script>

<style scoped>

</style>
